<!-- 屈光发育档案/角塑复查(回访人员复查列表) -->
<template>
  <el-dialog title="复查信息" :close-on-click-modal="false" :visible.sync="visible" center append-to-body fullscreen>
    <el-button class="miui-dialog-close-btn" @click="visible = false">关闭页面</el-button>
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">

    <div class="mod-config">
      <div class="avue-crud">
        <el-table :data="dataList" border v-loading="dataListLoading">
          <el-table-column prop="checkDate" label="检查时间"></el-table-column>
          <el-table-column prop="personName" label="姓名"></el-table-column>
          <el-table-column prop="telPhone" label="联系电话"></el-table-column>
          <el-table-column prop="deptName" label="就诊部门"></el-table-column>
          <el-table-column prop="checkDoctorName" label="主检医生"></el-table-column>
          <el-table-column prop="uniqueCode" label="ID号"></el-table-column>
          <el-table-column prop="customerCard" label="就诊卡号"></el-table-column>
          <el-table-column prop="nextCheckDate" label="预约复查"></el-table-column>
          <el-table-column prop="checkType" label="检查类型" :formatter="checkTypeFormatter"></el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button v-if="permissions.pvm_ckcorneal_edit" type="text" icon="el-icon-edit" @click="addOrUpdateHandle(scope.row.id,2,scope.row.docId)">复诊</el-button>
              <el-button v-if="permissions.pvm_ckcorneal_del" type="text" icon="el-icon-delete" @click="deleteHandle(scope.row.id)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <div class="avue-crud__pagination">
        <el-pagination
          @size-change="sizeChangeHandle"
          @current-change="currentChangeHandle"
          :current-page="pageIndex"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="pageSize"
          :total="totalPage"
          background
          layout="total, sizes, prev, pager, next">
        </el-pagination>
      </div>
      <table-form v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></table-form>
      </div>
    </el-form>
  </el-dialog>
</template>




<script>
  import {fetchCkCornealList, delCkCornealObj} from '@/api/pvm/ckcorneal'
  import { filterParams } from "@/util/tools"
  import TableForm from './form'
  import {mapGetters} from 'vuex'
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          key: ''
        },
        dataList: [],
        searchShow:true,
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        addOrUpdateVisible: false
      }
    },
    components: {
      TableForm
    },
    computed: {
      ...mapGetters(['permissions'])
    },
    methods: {
      init(personId){
        this.visible = true
        this.dataForm.personId = personId || ''
        this.getDataList();
      },
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        let params1 = filterParams(this.dataForm);
        let params2 = { current: this.pageIndex, size: this.pageSize};
        fetchCkCornealList(Object.assign(params2, params1)).then(response => {
          if(response.data.code == '0'){
            this.dataList = response.data.data.records
            this.totalPage = response.data.data.total
          }else{
            this.$message.error(response.data.mdg)
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 新增 / 修改
      addOrUpdateHandle (id,checkType,docId) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id,checkType,'常规检查',docId)
        })
      },
      // 删除
      deleteHandle (id) {
        this.$confirm('是否确认删除ID为' + id, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function () {
          return delCkCornealObj(id)
        }).then(response => {
          if(response.data.code == '0'){
            this.$message.success('删除成功')
            this.getDataList()
          }else{
            this.$message.error(response.data.mdg)
          }
        })
      },
      searchChange() {
        this.pageIndex=1;
        this.getDataList()
      },
      // 搜索清空
      searchReset () {
        this.$refs.searchForm.resetFields();
        this.getDataList(this.page)
      },
      handleSearchShow () {
        this.searchShow = !this.searchShow;
      },
      // 刷新回调
      refreshChange() {
        this.getDataList(this.page)
      },
      checkTypeFormatter(row, column, cellValue, index) {
        switch (cellValue) {
          case 1:
            return '初检'
            break
          case 2:
            return '复诊'
            break
        }
      },
    }
  }
</script>
